/**
 *
 */
package com.yangtao.framework.hibernate;

import org.hibernate.criterion.Example.PropertySelector;
import org.hibernate.type.Type;

import java.util.Collection;

/**
 * 非空的属性选择器，用户查询对象的查询
 *
 * @author 杨涛
 * @version 1.0
 */
public class NotEmptyPropertySelector implements PropertySelector {

	/**
	 *
	 */
	private static final long serialVersionUID = 1L;

	@SuppressWarnings("unchecked")
	@Override
	public boolean include(Object propertyValue, String propertyName, Type type) {
		if (propertyValue == null) {
			return false;
		}
		if (propertyValue instanceof String && "".equals(propertyValue)) {
			return false;
		}
		if (propertyValue instanceof Collection) {
			return ((Collection) propertyValue).size() != 0;
		}
		return true;
	}

}
